package com.syni.mdd.yhd.common.all.controller.protect.common;

import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.sjb.common.component.utils.common.annotations.CheckParams;
import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.constants.ResultMsg;
import com.syni.mdd.yhd.common.all.service.BmsBusinessService;
import com.syni.mdd.yhd.common.all.service.BmsCommonService;
import com.syni.mdd.sjb.common.component.utils.common.utils.ParamsMap;
import com.syni.mdd.sjb.common.component.utils.redis.utils.RedisTemplateUtils;;
import com.syni.mdd.yhd.common.all.utils.TokenUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * @className BmsCommonController
 * @description TOO
 * @Author cfx
 * @DATE 2019/5/29 9:31
 * @VERSION 1.0
 **/
@RestController
@RequestMapping("/common")
public class BmsCommonController {
    @Autowired
    BmsCommonService bmsCommonService;

    @Autowired
    BmsBusinessService bmsBusinessService;

    @PostMapping("/getUploadVideoSign")
    @CheckParams(checkAuth = true)
    public Map<String,Object> getUploadVideoSign(@RequestBody Map<String,Object> paramsMap){
        return bmsCommonService.getUploadVideoSign();
    }

    @PostMapping("/uploadVideo")
    public Map<String,Object> uploadVideo(@RequestParam(name = "videoFile") MultipartFile uploadFile){
        return bmsCommonService.uploadVideoFile(uploadFile);
    }

    @PostMapping("/uploadImgFileEnhance")
    public Map<String,Object> uploadImgFileEnhance(@RequestParam(name = "imgFile") MultipartFile[] uploadFiles, @RequestParam(name = "imgType") Integer fileType){
        return bmsCommonService.uploadImgFileEnhance(uploadFiles,fileType);
    }

    @PostMapping("/uploadImgFile")
    public Map<String,Object> uploadImgFile(@RequestParam(name = "imgFile") MultipartFile[] uploadFiles, @RequestParam(name = "imgType") Integer fileType){
        return bmsCommonService.uploadMoreImgFile(uploadFiles,fileType);
    }

    @PostMapping("/uploadImgFileEnhance_v2")
    public Map<String,Object> uploadImgFileEnhance_v2(@RequestParam(name = "imgFile") MultipartFile[] uploadFiles, @RequestParam(name = "imgType") Integer fileType){
        return bmsCommonService.uploadImgFileEnhance_v2(uploadFiles,fileType);
    }

    @PostMapping("/uploadImgFile_v2")
    public Map<String,Object> uploadImgFile_v2(@RequestParam(name = "imgFile") MultipartFile[] uploadFiles, @RequestParam(name = "imgType") Integer fileType){
        return bmsCommonService.uploadMoreImgFile_v2(uploadFiles,fileType);
    }

    @PostMapping("/checkPhoneRegister")
    @CheckParams(params = {"phone"})
    public Map<String,Object> checkPhoneRegister(@RequestBody Map<String,Object> paramsMap){
        String phone = paramsMap.get("phone").toString();
        return bmsCommonService.checkPhoneRegister(phone);
    }

    @PostMapping("/checkPhoneIsRegister")
    @CheckParams(params = {"phone"})
    public Map<String,Object> checkPhoneIsRegister(@RequestBody Map<String,Object> paramsMap){
        String phone = paramsMap.get("phone").toString();
        return bmsCommonService.checkPhoneIsRegister(phone);
    }

    @PostMapping("/saveUserLocation")
    @CheckParams
    public Map<String,Object> saveUserLocation(@RequestBody ParamsMap paramsMap){

        return bmsCommonService.saveUserLocation(paramsMap);
    }

    @PostMapping("/getServerData")
    @CheckParams
    public Map<String,Object> getServerData(@RequestBody ParamsMap paramsMap){
        return bmsCommonService.getServerData(paramsMap);
    }

    @GetMapping("/info")
    public Map<String,Object> getServerData(){
        Map<String,Object> paramsMap = new HashMap<>();
        paramsMap.put("info","dspApi服务器");
        return paramsMap;
    }

    @PostMapping("/checkToken")
    public Map<String,Object> checkToken(@RequestBody ParamsMap paramsMap){
        Integer userId = paramsMap.getInteger("userId");
        String token = paramsMap.getString("token");
        //String redisKey = Constants.REDIS_KEY_TOKEN_RECORD + token;
        //String redisKey = RedisTemplateUtils.getRedisTemplate().hasKey(token)
        String Token = TokenUtils.getToken(userId.toString(),String.valueOf(Constants.GENERAL_USER_ROLE_ID),true);
        Map<String,Object> resultMap = new HashMap();
        resultMap.put("userid",userId);
        resultMap.put("token",Token);
        return ResultMapHelper.success(resultMap, ResultMsg.MSG_GET_SUCCESS);
    }

}
